package main

import (
	"fmt"
	"log"
	"net/rpc"
)

const (
	HelloServiceName = "com.zy.HelloService"
)

type HelloServiceClient struct {
	Client *rpc.Client
}

func DialHelloService(network, address string) (*HelloServiceClient, error) {
	dial, err := rpc.Dial(network, address)
	if err != nil {
		log.Fatal("Dial Exception：", err)
	}
	return &HelloServiceClient{Client: dial}, err
}

func (p *HelloServiceClient) Hello(request string, reply *string) error {
	return p.Client.Call(HelloServiceName+".Hello", request, reply)
}

/**
  客户端
*/
func main() {
	//在指定的网络和地址与RPC服务端连接
	client, err := DialHelloService("tcp", "localhost:8088")
	var reply string
	//Call调用指定的方法，等待调用返回，将结果写入reply，然后返回执行的错误状态。
	err = client.Hello("hello", &reply)
	if err != nil {
		log.Fatal("client Call Exception：", err)
	}
	fmt.Println(reply)
}
